<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>论坛头部</title>

    <!-- CSS================================================== -->
    <link rel="stylesheet" href="/static/css/zerogrid.css">
    <link rel="stylesheet" href="/static/css/head.css">
    <link rel="stylesheet" href="/static/css/css.css">
    <link rel="stylesheet" href="/static/css/responsive.css">
    <script type="text/javascript" src="/static/js/jquery-3.4.1.js"></script>

</head>
<body>

<div class="wrap-body">
    <!----------------------------Header------------------------------------>
    <header>
        <div class="wrap-header zerogrid">
            <nav>
                <div class="wrap-nav">
                    <div class="menu">
                        <ul>
                            <li><a href="index">首页</a></li>
                            <c:if test="${user!=null}">
                                <li><a href="myCenter">个人</a></li>
                                <li><a href="post">发表帖子</a></li>
                                <li><a href="#" onclick="isExit()">${user.userName}</a></li>
                            </c:if>

                            <c:if test="${user==null}">
                                <li><a href="login">登录</a></li>
                            </c:if>
                            <li><a>|</a></li>
                            <li><input type="text" alt="搜索帖子标题" id="str"></li>
                            <li><a href="#" onclick="postSeek()">搜索</a></li>
                        </ul>
                    </div>
                </div>
            </nav>
        </div>
    </header>
    <!----------------------------Header-end------------------------------------>

</div>
</body>
<script>
    function isExit() {
        if (confirm("是否退出当前帐号?")) {
            $.ajax({
                url: "/exit",
                method: 'get',
                success: function (data) {
                    console.log(data.info);
                    window.location.href = 'index';
                },
                error: function () {
                    alert("请求出错")
                }
            })
        }
    }

    function postSeek() {
        $.ajax({
            url: '/postSeek',
            method: 'post',
            data: {
                postTitle: $('#str').val(),
            },
            dataType: 'json',
            success: function (data) {
                console.log(data.info);
                window.location.href = "/postSeek";
            },
            error: function () {
                alert("请求出错")
            },
        })
    }
</script>
</html>